package com.waghost.bridalgown.controller;

import com.waghost.bridalgown.annotaion.Logging;
import com.waghost.bridalgown.entity.Reserve;
import com.waghost.bridalgown.entity.Result;
import com.waghost.bridalgown.entity.UserBgLike;
import com.waghost.bridalgown.entity.UserInfo;
import com.waghost.bridalgown.service.ReserveService;
import com.waghost.bridalgown.service.UserBgLikeService;
import com.waghost.bridalgown.utils.UserUtils;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
// 订单
@RestController
@CrossOrigin
@AllArgsConstructor
@RequestMapping("/reserve")
public class ReserveController {

    private ReserveService reserveService;
    private UserUtils utils;
    @GetMapping("/list")
    public Result list() {
        return reserveService.list();
    }
    @GetMapping("/get/{id}")
    public Result get(@PathVariable Integer id) {
        return reserveService.getOrder(id);
    }

    // 通过订单状态查询
    @GetMapping("/getStatus/{status}")
    public Result getStatus(@PathVariable Integer status,HttpServletRequest request) {
        UserInfo user = utils.getUser(request);
        return reserveService.getStatus(status,user.getId());
    }
    @GetMapping("/get")
    public Result get(HttpServletRequest request) {
        UserInfo user = utils.getUser(request);
        return reserveService.getId(user.getId());
    }

    @PostMapping("/add")
    @Logging(type = 1,uuid = 5)
    public Result addUser(@RequestBody Reserve reserve, HttpServletRequest request) {
        reserve.setUserId(utils.getUser(request).getId());
        return reserveService.add(reserve);
    }

    @PostMapping("/edit")
    @Logging(type = 3,uuid = 5)
    public Result editUser(@RequestBody Reserve reserve) {
        System.out.println(reserve);
        return reserveService.update(reserve);
    }

    @PostMapping("/del/{id}")
    @Logging(type = 2,uuid = 5)
    public Result delUser(@PathVariable("id") Integer id) {
        return reserveService.delete(id);
    }


}
